<div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
        <div class="layui-card hxr-layui-card">
            <!-- <div class="layui-form hxradmin-card-header">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">代理用户名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="users" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn" data-type="reload" id="searchs">搜索</button>
                    </div>
                </div>
            </div> -->
            <div class="layui-card-body">
                <table class="layui-hide" id="list-select-table" lay-filter="list-select-table"></table>
                </script>
            </div>
        </div>
    </div>
</div>
<div class="form-btn" style="bottom: -20px;">
    <input type="button" value="确认选择" class="layui-btn selectok">
</div>
<script>
    //表格数据渲染
    layui.use(['table', 'form'], function() {
        var table = layui.table,
            form = layui.form,
            $ = layui.$;
        layui.admin.initlist(table,'agents/list', 275, [
            [{
                type: 'radio'
            }, {
                field: 'agent_id',
                title: 'ID',
                width: 100
            }, {
                field: 'agent_name',
                title: '代理用户名',
                minWidth: 150
            }, {
                field: 'real_name',
                title: '姓名',
                minWidth: 100
            },  {
                field: 'tel',
                title: '电话',
                width: 150
            },  {
                field: 'address',
                title: '住址',
                width: 150
            }]
        ],'#list-select-table',465,{obj:layui.admin.member,val1:'agent_id',val2:'agent_id'},{'band':1})
        //搜索
        $('#searchs').on('click', function() {
            var val1 = $('input[name="users"]').val()

            //执行重载
            table.reload('list-select-table', {
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    search_text: val1
                }
            });
        });
        $('.selectok').click(function(){
            var checkStatus = table.checkStatus('list-select-table')
                ,checkData = checkStatus.data[0];

            if(!checkData){
                layer.msg('请选择代理商');
            }else{
                if(layui.admin.objData.type==3){
                    layui.admin.formapi('members/set_administer',{
                        member_id:layui.admin.member.member_id,
                        id:checkData.agent_id,
                        type:2
                    });
                }else{

                    layer.close(layui.admin.pups);
                }
            }
        });
    });
</script>
